/**
 * @author SaoE
 * @date 2025/2/21 15:13
 */
public class _114 {
    public void flatten(TreeNode root) {
        afterOrder(root);
    }

    public void afterOrder(TreeNode root) {
        if (root == null){
            return;
        }
        afterOrder(root.left);
        afterOrder(root.right);

        TreeNode temp1 = root.right;
        root.right = root.left;
        root.left = null;

        // 关键temp
        TreeNode temp2 = root;
        while (temp2.right != null){
            temp2 = temp2.right;
        }
        temp2.right = temp1;

    }
}
